<?
  require_once("connection.php");
  error_reporting(0);
?>
<html>
<head>
<script>
/*
jQuery(document).ready(function() {
    jQuery('#upload_image_button').click(function() {
        formfield = jQuery('#upload_image').attr('name');
        tb_show('', 'media-upload.php?type=image&TB_iframe=true');
        return false;
    });

    window.send_to_editor = function(html) {
        imgurl = jQuery('img',html).attr('src');
        jQuery('#upload_image').val(imgurl);
        tb_remove();
    }
});*/
//-----------------------------------------------------------------------------
function lecture_slide_browse(lecture_id){
    formfield = jQuery('#upload_image').attr('name');
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    document.getElementById("update"+lecture_id).disabled = false;
}
//-----------------------------------------------------------------------------
function lecture_additional_browse(lecture_id){
    formfield = jQuery('#upload_image').attr('name');
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    document.getElementById("update_"+lecture_id).disabled = false;
}

</script>
</head>
<body>

  <div style="margin-left:300px;font-size:18;font-familyt:Arial">Lectures</div>
  <table width="100%">
    <tbody>
      <tr>
        <td>
          <a href="#" style="text-decoration:none;" onclick="add_lecture(0,0);return false;">
            <font size='2' color='blue'>
              Add new lecture
      	    </font>
  	  	  </a>
  	    </td>
  	  </tr>
    </tbody>
  </table>
  <br>


  <?
    if(isset($_POST["course_id"]))
      $course_id=$_POST["course_id"];
    else
      $course_id=0;

    $query = "select * from g_courses;";
    $result = @mysql_query($query);
    
	    echo "<select id='course' onchange='c_l_change(this);return false;'>";
	    if($course_id==0)
	      echo "<option value='0' selected>All Courses</option>";
	    else
          echo "<option value='0'>All Courses</option>";
	    while($row=@mysql_fetch_array($result)){
          if($course_id==$row["course_id"])
            echo "<option value='".$row["course_id"]."' selected>".$row["name"]." - ".$row["year"]." ".$row["semester"]."</option>";
          else
            echo "<option value='".$row["course_id"]."'>".$row["name"]." - ".$row["year"]." ".$row["semester"]."</option>";
	    }
	    echo "</select>";


    if($course_id!=0)
      $query = "select * from g_lectures t1, g_courses t2 where t1.course_id=t2.course_id and t1.course_id=".$_POST["course_id"]." order by date;";
    else
      $query = "select * from g_lectures t1, g_courses t2 where t1.course_id=t2.course_id order by date;";
    $result = @mysql_query($query);
    
    $row_number = @mysql_num_rows($result);
    
    echo " Rows: ".$row_number;

    if($row_number>0){
	    echo "<table class='tbl_2'><tbody>";
	    echo "<tr class='inside'>";
	    echo "<th>&nbsp;</th>";
	    echo "<th>&nbsp;</th>";
	    //echo "<th><a href='#' onclick='return false;display_table(2,1);return false;'>lecture_id</a></th>";
	    //echo "<th><a href='#' onclick='return false;display_table(2,2);return false;'>seq_number</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(2,3);return false;'>date</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(2,4);return false;'>description</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(2,5);return false;'>slide</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(2,6);return false;'>additional</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(2,7);return false;'>course_name</a></th>";
	    echo "</tr>";
	    while($row = @mysql_fetch_array($result)){
	        //echo "<tr class='inside' id='OnMouseTr".$row[0]."' style='background:#EAF7EB' onmouseover='mouse_over(".$row[0].");return false;' onmouseout='mouse_out(".$row[0].");return false;'>";
	        echo "<tr class='inside' id='OnMouseTr".$row[0]."' style='background:#EAF7EB' >";
	        echo "<td><a href='#' id='".$row[0]."' onclick='delete_lecture(".$row[0]."); return false;'><img border='0' alt='Delete' src='../wp-content/plugins/course_management/images/delete.png'/></a></td>";
	        echo "<td><a href='#' id='".$row[0]."' onclick='add_lecture(1,".$row[0]."); return false;'><img border='0' alt='Edit' src='../wp-content/plugins/course_management/images/edit.png'/></a></td>";
            //echo "<td>".$row["lecture_id"]."</td>";
	        //echo "<td>".$row["seq_num"]."</td>";
	        echo "<td>".$row["date"]."</td>";
	        echo "<td>".$row["description"]."</td>";
	        if($row["slide"]!="none")
	          echo "<td><table><tr><td width='180px'><a href='".$row["slide_url"]."'>".$row["slide"]."</a></td><td align='right'><input id='upload_image_button".$row["lecture_id"]."' type='button' value='...' onclick='lecture_slide_browse(".$row["lecture_id"].")'/><button id='update".$row["lecture_id"]."' onclick='lecture_slide(".$row["lecture_id"].");' disabled>Upd</button></td></tr></table></td>";
	        else
              echo "<td><table><tr><td width='180px'>".$row["slide"]."</td><td align='right'><input id='upload_image_button".$row["lecture_id"]."' type='button' value='...' onclick='lecture_slide_browse(".$row["lecture_id"].")'/><button id='update".$row["lecture_id"]."' onclick='lecture_slide(".$row["lecture_id"].");' disabled>Upd</button></td></tr></table></td>";
            if($row["additional"]!="none")
              echo "<td><table><tr><td width='180px'><a href='".$row["additional_url"]."'>".$row["additional"]."</a></td><td align='right'><input id='upload_image_button_".$row["lecture_id"]."' type='button' value='...' onclick='lecture_additional_browse(".$row["lecture_id"].")'/><button id='update_".$row["lecture_id"]."' onclick='lecture_additional(".$row["lecture_id"].");' disabled>Upd</button></td></tr></table></td>";
            else
              echo "<td><table><tr><td width='180px'>".$row["additional"]."</td><td align='right'><input id='upload_image_button_".$row["lecture_id"]."' type='button' value='...' onclick='lecture_additional_browse(".$row["lecture_id"].")'/><button id='update_".$row["lecture_id"]."' onclick='lecture_additional(".$row["lecture_id"].");' disabled>Upd</button></td></tr></table></td>";
	        echo "<td>".$row["name"]." - ".$row["year"]." ".$row["semester"]."</td>";
	        echo "</tr>";
	    }
	echo "</tbody></table>";
	}
	else{
        die("<br>There are no lectures!!!");
        exit;
	}
  ?>

</body>

</html>
